home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 016a / dvcron10.zip / GETOPT.C < prev    next >
Text File  |  1991-12-18  |  856b  |  45 lines

  1. /*
  2.   copyright (c) 1991 -- kyle a. york
  3.   use / copy / modify at will: please see CRON.DOC for details
  4. */
  5. #include <alloc.h>
  6. #include <stdio.h>
  7. #include "getopt.h"
  8.  
  9. /*
  10.   getopt.c
  11.  
  12.   return any switches found in the command string
  13.   each letter == a legal switch, a ':' following a letter means
  14.   that a number should follow
  15. */
  16.  
  17. int  optind=0;
  18. char *optarg=NULL;
  19.  
  20. int getopt(int argc, char **argv, char *optstring)
  21. {
  22.   char *ptr;
  23.  
  24.   if (!optind)
  25.     optind=1;
  26.  
  27.   if ((optind > argc) || (argv[optind][0] != '-'))
  28.     return(EOF);
  29.  
  30.   for (ptr=optstring; argv[optind][1] != *ptr; ptr++);
  31.   if (!*ptr)
  32.     return('?');
  33.   if (*(ptr+1) == ':') {
  34.     if (argv[optind][2])
  35.       optarg=argv[optind]+2;
  36.     else {
  37.       optarg=argv[optind+1];
  38.       optind++;
  39.     }
  40.   } else
  41.     optarg=NULL;
  42.   optind++;
  43.   return(*ptr);
  44. }
  45.